package my_account;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class My_cart_link_product extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

    @Test
  public void testUntitled10() throws Exception {
	/*driver.get(baseUrl);
    driver.findElement(By.linkText("My Account")).click();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys("qatestingtestqa@gmail.com");
    driver.findElement(By.id("pass")).clear();
    driver.findElement(By.id("pass")).sendKeys("qwerty");
    driver.findElement(By.id("send2")).click();*/
    	driver.get(baseUrl + "/customer/account/");
    	 driver.get(baseUrl + "/furniture/living-room.html");
    	    driver.findElement(By.cssSelector("li.item.last > div.actions > button.button.btn-cart")).click();
    	    driver.findElement(By.linkText("My Account")).click();
    try {
      assertEquals("Couch", driver.findElement(By.linkText("Couch")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    driver.findElement(By.linkText("Couch")).click();
    try {
      assertEquals("Couch", driver.findElement(By.cssSelector("h1")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    driver.get(baseUrl + "/customer/account/");
    driver.findElement(By.linkText("Remove This Item")).click();
    assertTrue(closeAlertAndGetItsText().matches("^Are you sure you would like to remove this item from the shopping cart[\\s\\S]$"));
  }

   private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  
  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}
